package com.king.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker   //表示开启使用STOMP协议来传输基于代理的消息
@EnableAsync //开启异步
public class WebsocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket") //注册一个端点，websocket的访问地址
                .withSockJS();//如浏览器不兼容，可自动进行降级技术处理
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //推送消息的前缀，user:点对点的推送，topic：广播式的发布-订阅的推送
        registry.enableSimpleBroker("/user/","/topic/");

        //以/app开头的就会进入代理点、websocket
        registry.setApplicationDestinationPrefixes("/app");
    }
}
